package com.howells.time.module.setting.view;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.howells.time.R;
import com.howells.time.base.http.HttpURL;
import com.howells.time.base.http.ServerAddress;
import com.howells.time.base.utils.SharedPrefsUtil;
import com.howells.time.base.utils.StatusBarUtil;
import com.howells.time.base.utils.ToastShow;

public class ConfigActivity extends AppCompatActivity {

    private EditText mEditIp;
    private EditText mEditPort;
    private EditText mEditName;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_config);
        StatusBarUtil.setColor(this,0);
        TextView title= (TextView) findViewById(R.id.top_pannel_title);
        title.setText("配置服务器");
        mEditIp= (EditText) findViewById(R.id.text_ip);
        mEditPort= (EditText) findViewById(R.id.text_port);
        mEditName= (EditText) findViewById(R.id.text_name);
        mEditIp.setText(ServerAddress.ServerIp.toString());
        mEditPort.setText(ServerAddress.ServerPort.toString());
        mEditName.setText(ServerAddress.ServerName.toString());
    }

    public void onClick(View view){
        switch (view.getId()){
            case R.id.top_pannel_back:
                finish();
                break;
            case R.id.saveconfig:
                mEditIp= (EditText) findViewById(R.id.text_ip);
                mEditPort= (EditText) findViewById(R.id.text_port);
                mEditName= (EditText) findViewById(R.id.text_name);
                SharedPrefsUtil.putValue(getApplicationContext(),"server_config","server_ip",mEditIp.getText().toString());
                SharedPrefsUtil.putValue(getApplicationContext(),"server_config","server_port",mEditPort.getText().toString());
                SharedPrefsUtil.putValue(getApplicationContext(),"server_config","server_name",mEditName.getText().toString());

                ServerAddress.ServerIp.setCode(mEditIp.getText().toString());
                ServerAddress.ServerPort.setCode(mEditPort.getText().toString());
                finish();
                ToastShow.ToastLong(this,HttpURL.LoginApi.toString());
                break;
        }
    }
}
